package com.eonmind.pay.controller;

import com.eonmind.common.contract.data.response.ResponseEntity;
import com.eonmind.common.provider.entity.pay.Cart;
import com.eonmind.common.security.annotations.UserInfo;
import com.eonmind.pay.dto.CartDto;
import com.eonmind.pay.service.CartService;
import com.eonmind.user.contract.dto.UserInfoData;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName CartController
 * @Description TODO
 * Author 32004
 * Date 2025/5/20 15:03
 * Version 1.0
 **/

@Slf4j
@RestController
@RequestMapping("/cart")
public class CartController {

    @Resource
    CartService cartService;

    /**
     * 获取购物车列表
     *
     * @return
     * @ignoreParams userInfoData
     */
    @GetMapping("/list")
    @UserInfo
    public ResponseEntity<CartDto> list(UserInfoData userInfoData){
        return cartService.getListByUserId(userInfoData.getId());
    }

    /**
     * 购物车列表商品修改
     *
     * @param cart
     * @return
     * @ignoreParams userInfoData
     */
    @PostMapping("/update")
    @UserInfo
    public ResponseEntity update(UserInfoData userInfoData,@RequestBody Cart cart){
        return cartService.addCartByUserId(cart,userInfoData.getId());
    }


}
